/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package net.alteiar.plateform;

import jade.core.Agent;

import java.util.Iterator;

import net.alteiar.plateform.game.Vector2D;
import net.alteiar.plateform.game.World;
import net.alteiar.plateform.game.model.CharacterEntity;
import net.alteiar.plateform.game.model.Entity;
import net.alteiar.plateform.gui.RunnableGameLogic;
import net.alteiar.plateform.gui.RunnableUi;

/**
 * @author Cody Stoutenburg
 * 
 */
public class GamePlateformAgent extends Agent {
	private static final long serialVersionUID = 1L;

	private static final Long FRAME_PER_SEC = 60L;
	private static final Long GAME_UPDATE_PER_SEC = 30L;

	private World world;

	@Override
	protected void setup() {

		world = new World(30L, 30L);
		world.addEntity(new CharacterEntity(1, 10, 1, 1, 6));
		for (Entity character : world.getAllCharacters()) {
			character.setSpeed(new Vector2D(5.0, 0.0));
		}

		world.addEntity(new CharacterEntity(1, 1, 1, 1, 1.3));
		Iterator<Entity> itt = world.getAllCharacters().iterator();
		itt.next();
		itt.next().setSpeed(new Vector2D(0.0, 1.0));

		world.addEntity(new CharacterEntity(1, 5, 0.5, 0.5, 1.3));
		itt = world.getAllCharacters().iterator();
		itt.next();
		itt.next();
		itt.next().setSpeed(new Vector2D(0.0, -1.0));

		RunnableUi ui = new RunnableUi(world, FRAME_PER_SEC);
		RunnableGameLogic gameLogic = new RunnableGameLogic(world,
				GAME_UPDATE_PER_SEC);

		Thread th = new Thread(ui);
		th.start();

		Thread game = new Thread(gameLogic);
		game.start();
	}

	public World getWorld() {
		return world;
	}
}
